/**
 * 2017年5月3日
 */
package demo;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClientBuilder;

import com.drew.lang.BufferReader;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.edu.bjtu.general.math.Arrays;
import pojo.dto.services.DocumentVectorMessage;

/**
 * @author Alex
 *
 */
public class Main {
	public static void main(String args[]) throws ClientProtocolException, IOException{
		HttpClientBuilder dhb = HttpClientBuilder.create();
		HttpClient hc =  dhb.build();
		HttpPost hr = null;
		HttpHost hh =  new HttpHost("192.168.0.108", 8080);
		hr = new HttpPost("/post/transfile");
		HttpEntity he = MultipartEntityBuilder.create().addBinaryBody("file", new File("D:\\textdata\\userData\\c1\\1.txt")).build();
		hr.setEntity(he);
		HttpResponse response = hc.execute(hh, hr);
		HttpEntity re = response.getEntity();
		InputStream in = re.getContent();
		ObjectMapper om = new ObjectMapper();
		om.enableDefaultTyping();
		DocumentVectorMessage dvm = om.readValue(in, DocumentVectorMessage.class);
//		BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8"));
//		String line = null;
//		while((line=br.readLine())!=null){
//			System.out.println(line);
//		}
		System.out.println(dvm.getMsg());
	}
}
